From 61c430963fb3ec09ac2efb3ee50a636f8ac00f11 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 24 Jun 2025 16:08:29 -0400 Subject: [PATCH] prepare-root: Move metadata for deployment into otcore - Rename `mount_composefs` to `mount_rootfs` to make a little clearer what it does; even though if the rootfs is not composefs we don't do anything before. - But do always unconditionally update the metadata builder with the device/inode Prep for soft reboots. Signed-off-by: Colin Walters --- src/libotcore/otcore-prepare-root.c | 17 +++++++++++++---- src/libotcore/otcore.h | 14 +++++++------- src/switchroot/ostree-prepare-root.c | 13 ++----------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libotcore/otcore-prepare-root.c b/src/libotcore/otcore-prepare-root.c index fa990dec..a82e16d2 100644 --- a/src/libotcore/otcore-prepare-root.c +++ b/src/libotcore/otcore-prepare-root.c @@ -363,11 +363,20 @@ composefs_error_message (int errsv) #endif gboolean -otcore_mount_composefs (ComposefsConfig *composefs_config, GVariantBuilder *metadata_builder, - gboolean root_transient, const char *root_mountpoint, - const char *deploy_path, const char *mount_target, - bool *out_using_composefs, GError **error) +otcore_mount_rootfs (ComposefsConfig *composefs_config, GVariantBuilder *metadata_builder, + gboolean root_transient, const char *root_mountpoint, const char *deploy_path, + const char *mount_target, bool *out_using_composefs, GError **error) { + struct stat stbuf; + /* Record the underlying plain deployment directory (device,inode) pair + * so that it can be later checked by the sysroot code to figure out + * which deployment was booted. + */ + if (lstat (deploy_path, &stbuf) < 0) + return glnx_throw_errno_prefix (error, "lstat(%s)", deploy_path); + g_variant_builder_add (metadata_builder, "{sv}", OTCORE_RUN_BOOTED_KEY_BACKING_ROOTDEVINO, + g_variant_new ("(tt)", (guint64)stbuf.st_dev, (guint64)stbuf.st_ino)); + bool using_composefs = FALSE; #ifdef HAVE_COMPOSEFS /* We construct the new sysroot in /sysroot.tmp, which is either the composefs diff --git a/src/libotcore/otcore.h b/src/libotcore/otcore.h index 7a9978de..378878df 100644 --- a/src/libotcore/otcore.h +++ b/src/libotcore/otcore.h @@ -79,7 +79,7 @@ ComposefsConfig *otcore_load_composefs_config (const char *cmdline, GKeyFile *co gboolean load_keys, GError **error); /** - * otcore_mount_composefs: + * otcore_mount_rootfs: * @composefs_config: Configuration for composefs. * @metadata_builder: (transfer none): GVariantBuilder to add metadata to. * @root_transient: Whether the root filesystem is transient. @@ -89,15 +89,15 @@ ComposefsConfig *otcore_load_composefs_config (const char *cmdline, GKeyFile *co * @out_using_composefs: (out): Whether composefs was successfully used. * @error: (out): Return location for a GError, or %NULL. * - * Mounts a composefs image based on the provided configuration. + * If composefs is enabled, it will be mounted at the target. Otherwise, the + * target directory is left unchanged. * * Returns: %TRUE on success, %FALSE on error. */ -gboolean otcore_mount_composefs (ComposefsConfig *composefs_config, - GVariantBuilder *metadata_builder, gboolean root_transient, - const char *root_mountpoint, const char *deploy_path, - const char *mount_target, bool *out_using_composefs, - GError **error); +gboolean otcore_mount_rootfs (ComposefsConfig *composefs_config, GVariantBuilder *metadata_builder, + gboolean root_transient, const char *root_mountpoint, + const char *deploy_path, const char *mount_target, + bool *out_using_composefs, GError **error); // Our directory with transient state (eventually /run/ostree-booted should be a link to // /run/ostree/booted) diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index d3dee902..fb38f095 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -263,19 +263,10 @@ main (int argc, char *argv[]) GVariantBuilder metadata_builder; g_variant_builder_init (&metadata_builder, G_VARIANT_TYPE ("a{sv}")); - /* Record the underlying plain deployment directory (device,inode) pair - * so that it can be later checked by the sysroot code to figure out - * which deployment was booted. - */ - if (lstat (".", &stbuf) < 0) - err (EXIT_FAILURE, "lstat deploy_root"); - g_variant_builder_add (&metadata_builder, "{sv}", OTCORE_RUN_BOOTED_KEY_BACKING_ROOTDEVINO, - g_variant_new ("(tt)", (guint64)stbuf.st_dev, (guint64)stbuf.st_ino)); - // Tracks if we did successfully enable it at runtime bool using_composefs = false; - if (!otcore_mount_composefs (composefs_config, &metadata_builder, root_transient, root_mountpoint, - deploy_path, TMP_SYSROOT, &using_composefs, &error)) + if (!otcore_mount_rootfs (composefs_config, &metadata_builder, root_transient, root_mountpoint, + deploy_path, TMP_SYSROOT, &using_composefs, &error)) errx (EXIT_FAILURE, "Failed to mount composefs: %s", error->message); if (!using_composefs) -- 2.30.2